// pages/visitor/visitor.js
const { Tab, extend } = require('../../bower_components/zanui-weapp/dist/index');
const ini = require('../../common/init/init.js')
const conf = require('../../common/conf/conf.js')
var thisapp = getApp()
Page(extend({}, Tab, {

  /**
   * 页面的初始数据
   */
  data: {
    tab1: {
      list: [
        {
          id:'today',
          title:'今天'
        },
        {
          id:'last',
          title:'最近'
        }
      ],
      selectedId: 'today'
    },
    visitor:{},
    today:{},
    last:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this
    wx.request({
      url: conf.visitorPage.visitorUrl,
      method:"POST",
      data:{
        userInfo:thisapp.globalData.userInfo
      },
      dataType:"json",
      success:function(res){
        _this.setData({
          visitor: res.data.today,
          today:res.data.today,
          last:res.data.last
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  handleZanTabChange(e) {
    var componentId = e.componentId;
    var selectedId = e.selectedId;
    this.setData({
      [`${componentId}.selectedId`]: selectedId
    });
    if(selectedId == 'today'){
      this.setData({
        visitor: this.data.today
      })
    } else if (selectedId == 'last'){
      this.setData({
        visitor: this.data.last
      })
    }
  }
}))